<template>
  <div>
    <max-table :tableLoading="tableLoading"
               :tableData="tableData"
               :allColumns="allColumns"
               :tableTotal="tableTotal"
               :formDefaultData="formDefaultData"
               :formRule="formRule"
               @getData="getData"
               @addData="addData"
               @editData="editData"
               @deleteData="deleteData"/>
  </div>
</template>

<script>
import {defineComponent, ref} from "vue";
import {${entity}Page, ${entity}Save, ${entity}Update, ${entity}Remove} from "@/api/${properties.moduleName}/${name}.js";
import {message} from 'ant-design-vue';

export default defineComponent({
  setup() {
    /**
     * 参数列表：
     * tableLoading：表格加载状态
     * tableData：表格当页数据
     * allColumns：表格列配置
     * tableTotal：表格数据行数
     * formDefaultData：表单默认数据
     * formRule：表单数据规则
     */
    const tableLoading = ref(false);
    const tableData = ref([]);
    const allColumns = ref([
      <#list fields as field>
      {
        title: '${field.comment}',
        dataIndex: '${field.propertyName}',
        align: 'center',
        tableShow: true,
        formShow: true,
        formType: '${field.type.code}',
      },
      </#list>
    ]);
    const tableTotal = ref('0');
    const formDefaultData = ref({});
    const formRule = ref({});
    /**
     * 方法列表：
     * getData：获取表格数据
     * addData：新增数据
     * editData：修改数据
     * deleteData：删除数据
     */
    const getData = (page) => {
      tableLoading.value = true;
      ${entity}Page(page).then(result => {
        if (result.success) {
          tableData.value = result.obj.records;
          tableTotal.value = result.obj.total;
        }
        tableLoading.value = false;
      })
    }
    const addData = (data) => {
      ${entity}Save(data).then(result => {
        if (result.success) {
          message.success('新增成功');
        } else {
          message.error('新增失败');
        }
      })
    }
    const editData = (data) => {
      ${entity}Update(data).then(result => {
        if (result.success) {
          message.success('修改成功');
        } else {
          message.error('修改失败');
        }
      })
    }
    const deleteData = (data) => {
      ${entity}Remove(data).then(result => {
        if (result.success) {
          message.success('删除成功');
        } else {
          message.error('删除失败');
        }
      })
    }
    return {
        tableLoading,
        tableData,
        allColumns,
        tableTotal,
        formDefaultData,
        formRule,
        getData,
        addData,
        editData,
        deleteData
    };
  },
  components: {},
});
</script>

<style scoped>
</style>